package syyrjx.controller;

import syyrjx.jdbc.DataBase;
import syyrjx.jdbc.util.JDBCTool;

import java.io.IOException;

public class RegServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        this.reg(request, response);
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        this.reg(request, response);
    }
    private void reg(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        String username = request.getParameter("username");
        String userpwd = request.getParameter("userpwd");
        String sex = request.getParameter("sex");
        if(DataBase.register(JDBCTool.count,username,userpwd,sex)){
            response.sendRedirect("http://localhost:8080/onlineSystem/RegResult?res=1");
        }else{
            response.sendRedirect("http://localhost:8080/onlineSystem/RegResult?res=0");
        }
    }
}
